package cn.edu.sjtu.se.dslab.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import cn.edu.sjtu.se.dslab.action.bean.PageBean;
import cn.edu.sjtu.se.dslab.component.Component;
import cn.edu.sjtu.se.dslab.component.data.DataComponent;
import cn.edu.sjtu.se.dslab.component.design.DesignPatternComponent;
import cn.edu.sjtu.se.dslab.dao.IBaseDao;
import cn.edu.sjtu.se.dslab.dao.IDesignPatternComponentDao;
import cn.edu.sjtu.se.dslab.exception.DBException;

/**
 * 
 * @author longshaohang
 *
 */
@Repository("designPatternComponentDao")
public class DesignPatternComponentDaoImpl implements
		IDesignPatternComponentDao {

	@Resource(name = "baseDao")
	private IBaseDao<DesignPatternComponent> baseDao;

	@Override
	public void save(DesignPatternComponent dpComponent) {
		baseDao.save(dpComponent);
	}

	@Override
	public DesignPatternComponent update(DesignPatternComponent dpComponent) {
		return baseDao.update(dpComponent);
	}

	@Override
	public DesignPatternComponent queryById(long id) {
		return baseDao.queryById(DesignPatternComponent.class, id);
	}

	@Override
	public PageBean queryByPageNum(int pageNum) throws DBException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<DesignPatternComponent> queryByList() {
		return baseDao.queryList("DesignPatternComponent");
	}

	@Override
	public List<DesignPatternComponent> queryListByDesignPattern(int pageNo, int pageSize, String symbal) {
		StringBuffer hql = new StringBuffer("from DesignPatternComponent dpc where dpc.instance.designPattern.symbal='");
		hql.append(symbal);
		hql.append("'");
		return baseDao.querySpecialList(pageNo, pageSize, hql.toString());
	}

	@Override
	public DesignPatternComponent queryByUri(String uri) {
		StringBuffer hql = new StringBuffer("from DesignPatternComponent dpc where dpc.uri='");
		hql.append(uri);
		hql.append("'");
		return baseDao.queryObject(hql.toString());
	}

	@Override
	public List<DesignPatternComponent> queryListByProject(long projectId) {
		StringBuffer hql = new StringBuffer("from DesignPatternComponent dpc where dpc.project.id='");
		hql.append(projectId);
		hql.append("'");
		return baseDao.querySpecialList(1, 10, hql.toString());
	}

	@Override
	public DesignPatternComponent queryByType(long projectId, String type) {
		StringBuffer hql = new StringBuffer("from DesignPatternComponent dpc where dpc.type='");
		hql.append(type);
		hql.append("' and dpc.project.id='");
		hql.append(projectId);
		hql.append("'");
		return baseDao.queryObject(hql.toString());
	}

}
